package com.example.config;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
import javax.servlet.Filter;


public class ServletContainersInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer{

    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

//    //乱码
//    @Override
//    protected Filter[] getServletFilters() {
//        CharacterEncodingFilter filter=new CharacterEncodingFilter();
//        filter.setEncoding("UTF-8");
//        return new Filter[]{filter};
//    }
}

//public class ServletContainersInitConfig extends AbstractDispatcherServletInitializer {
//    //配置SpringMvc容器
//    protected WebApplicationContext createServletApplicationContext() {
//        AnnotationConfigWebApplicationContext applicationContext=new AnnotationConfigWebApplicationContext();
//        applicationContext.register(SpringMvcConfig.class);
//        return applicationContext;
//    }
//
//    //设置那些请求为SoringMvc处理
//    protected String[] getServletMappings() {
//        return new String[]{"/"};
//    }
//
//    protected WebApplicationContext createRootApplicationContext() {
//        AnnotationConfigWebApplicationContext applicationContext=new AnnotationConfigWebApplicationContext();
//        applicationContext.register(SpringConfig.class);
//        return applicationContext;
//    }
//}
